package com.example.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Configuration
@EnableConfigurationProperties(HelloServiceProperties.class)
//@ConditionalOnClass(HelloService.class)
@ConditionalOnProperty(prefix = "hello",value = "enabled",matchIfMissing=true)
public class HelloServiceAutoConfiguation {

    @Autowired
    private HelloServiceProperties helloServiceProperties; //@EnableConfigurationProperties(HelloServiceProperties.class)

    @Bean
    @ConditionalOnMissingBean(HelloService.class)
    public HelloService helloService(){
        HelloService helloService = new HelloService();
        System.out.println("---> ooo "+helloServiceProperties.getMsg());
        helloService.setMsg(helloServiceProperties.getMsg());
        return  helloService;
    }

//
//    HelloServiceAutoConfiguation matched:
//            - @ConditionalOnProperty (hello.enabled) matched (OnPropertyCondition)
//
//    HelloServiceAutoConfiguation#helloService matched:
//            - @ConditionalOnMissingBean (types: com.example.service.HelloService; SearchStrategy: all) did not find any beans (OnBeanCondition)

}
